home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / PageMakerClassLibrary / LowLevel / PPluginCall.cpp < prev    next >
C/C++ Source or Header  |  1996-08-20  |  4KB  |  136 lines

  1. /*
  2.  *--- PPluginCall.cpp -----------------------------------------------------
  3.  * Copyright (c) 1995-96 Adobe Systems Incorporated.  All rights reserved.
  4.  * Created on Thu, Oct 12, 1995 @ 9:50 PM by Paul Ferguson.
  5.  *
  6.  * Description:  For notes about this class, refer to the
  7.  * header file PPluginCall.h
  8.  *-------------------------------------------------------------------------
  9.  */
  10. #include <string.h>
  11.  
  12. #include "PPluginCall.h"
  13.  
  14. #include "CIBasic.h"
  15. #include "CIInterfaceManager.h"
  16. #include "PMInterfaceIDs.h"
  17.  
  18. extern PMMessage * gPMMessage;
  19. extern sPMParamBlockPtr gPB;
  20.  
  21. sPMParamBlockPtr PPluginCall::sPB = NULL;    // Stores the current executing param block
  22. PMMessage * PPluginCall::sPMMessage = NULL;
  23.  
  24. PPluginCall::PPluginCall()
  25. {
  26. // assert (message != NULL);
  27.     sPMMessage = gPMMessage;
  28.     sPB = gPB;    // it is up to the DoXXX() functions to decide whether they need the Command and Query param block
  29.     
  30. }
  31.  
  32. // Static factory function
  33.  
  34. void PPluginCall::Dispatch()
  35. {
  36.     switch (sPMMessage->opCode)
  37.     {
  38.     case kPMLoad:
  39.         DoLoad();
  40.         break;
  41.  
  42.     case kPMRegister:
  43.         DoRegister();
  44.         break;
  45.  
  46.     case kPMInvoke:
  47.         DoInvoke();
  48.         break;
  49.  
  50.     case kPMEvent:
  51.         DoEvent();
  52.         break;
  53.  
  54.     case kPMSysEvent:
  55.         DoSysEvent();
  56.         break;
  57.  
  58.     case kPMAcquireInterface:
  59.         DoAcquireInterface();
  60.         break;
  61.  
  62.     case kPMReleaseInterface:
  63.         DoReleaseInterface();
  64.         break;
  65.  
  66.     case kPMUnload:
  67.         DoUnload();
  68.         break;
  69.  
  70.     case kPMShutdown:
  71.         DoShutdown();
  72.         break;
  73.     
  74.     default:
  75.         return;
  76.         break;        // do nothing
  77.     }    
  78. }
  79.  
  80.  
  81. /*
  82.  *--- BuildErrorMessages ---------------------------------------
  83.  *    This is a utility routine that takes a string parameter,
  84.  *    allocates a handle for it, and stuffs it in the 
  85.  *    errMessage field of the parameter block.
  86.  *
  87.  *    Note:   The handle becomes property of PageMaker, which
  88.  *            will free the handle after it's displayed.
  89.  *
  90.  * BULLSHIT: Does the error message handler still use handles?
  91.  *                If so, need to restore this function to the
  92.  *                way it was in 6.0.
  93.  *--------------------------------------------------------------
  94.  */
  95. void PPluginCall::BuildErrorMessages(const char * errText, const char * cantText)
  96. {
  97.     
  98.     sPB->errMessage = NULL;
  99.     
  100.     if (errText == NULL)
  101.         return;
  102.     
  103.     CIBasic * basicInterface; // = dynamic_cast<CIBasic *> (interface);
  104.  
  105.     gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
  106.     
  107.     size_t lenErrText  = strlen(errText);
  108.     size_t lenCantText = cantText ? strlen(cantText) : 0;
  109.  
  110.     //---------------------------------------------------------
  111.     // PageMaker requires that its strings be padded to
  112.     // even-byte boundaries, and have an extra null character
  113.     // at the end of the first or second string, so we add
  114.     // a little extra room.
  115.     //---------------------------------------------------------
  116.     char * ch = (char *) basicInterface->PMMemAlloc(lenErrText + lenCantText + 5);
  117.     if (errText)
  118.         strcpy(ch, errText);
  119.     
  120.     //---------------------------------------------------------
  121.     // The "Can't" message is optional.  If it's present,
  122.     // PageMaker does not display it's default "Cant" message.
  123.     // Make sure to start on even byte boundary.
  124.     //---------------------------------------------------------
  125.     if (cantText)
  126.     {
  127.         short i = lenErrText + (lenErrText & 0x01 ? 1 : 2);
  128.         strcpy(&ch[i], cantText);
  129.     }
  130.     sPB->errMessage = (PMHandle) ch;
  131.     
  132.     gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
  133. }
  134.  
  135. // end of PPluginCall.cpp
  136.